import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        shoplist: [{
            "number": "1",
            "name": "李女士",
            "phone": "13512345678",
            "address": "开封市龙亭区",
            "image": "../../static/teacher/teacher1.png",
            "order_price": 199,
            "time": "2023年12月1日 15:00"
        }, {
            "number": "2",
            "name": "王小姐",
            "phone": "13712345678",
            "address": "开封市龙亭区",
            "image": "../../static/teacher/teacher2.png",
            "order_price": 299,
            "time": "2023年12月3日 18:00"
        }, {
            "number": "3",
            "name": "赵先生",
            "phone": "15012345678",
            "address": "开封市龙亭区",
            "image": "../../static/teacher/teacher3.png",
            "order_price": 399,
            "time": "2023年12月5日 19:00"
        }],

        // orders: [{
        //     "technicians_number": "1",
        //     "technicians_name": "李师傅",
        //     "technicians_phone": "13512345678",
        //     "order_price": 199,
        //     "create_time": 1564731518
        // }, {
        //     "technicians_number": "2",
        //     "technicians_name": "王师傅",
        //     "technicians_phone": "13712345678",
        //     "order_price": 299,
        //     "create_time": 1564731518
        // }, {
        //     "technicians_number": "3",
        //     "technicians_name": "赵师傅",
        //     "technicians_phone": "15012345678",
        //     "order_price": 399,
        //     "create_time": 1564731518
        // }],
        //Tabs数据
        Tabs: [{
            id: 0,
            name: '推荐体验师',
            isActive: true
        }, {
            id: 1,
            name: '体检报告栏',
            isActive: false
        }, {
            id: 2,
            name: '云养艾草',
            isActive: false
        }, {
            id: 3,
            name: '艾灸历史',
            isActive: false
        }]
    },
    onShow(options) {
        //判断是否登陆
        const token = wx.getStorageSync('token')
        if (!token) {
            wx.navigateTo({
                url: '/pages/auth/auth',
            });
            return;
        }

        let pages = getCurrentPages();
        let { type } = pages[pages.length - 1].options;
        this.getOrderList(type)
    },
    //获取订单方法
    async getOrderList(type) {
        // const res = await request({ url: '/my/orders/all' }, { data: type })
        // this.setData({
        //     orders: res.orders.map(v => ({...v, create_time_cn: (new Date(v.create_time * 1000).toLocaleString()) }))
        // })
        //const res = await request({ url: '/my/orders/all' }, { data: type })
        let orders = this.data.orders;
        let newOrders = orders.map(v => ({ ...v, create_time_cn: (new Date(v.create_time * 1000).toLocaleString()) }))
        this.setData({
            orders: newOrders
        })
    },
    //切换Tab栏
    tabsItemChange(e) {
        const id = e.detail.id;
        const Tabs = this.data.Tabs;
        Tabs.forEach((v, i) => i === id ? v.isActive = true : v.isActive = false)

        if (id === 1) {
            wx.navigateTo({
                url: '/pages/checkup/checkup'
            });
            v.isActive = true
        }else if(id === 2){
            wx.navigateTo({
                url: '/pages/plant/plant'
            });
            v.isActive = true
        }
        this.setData({
            Tabs
        })

    }
})